#include "sql_compiler_cpp/Lexer.h"
#include "sql_compiler_cpp/Parser.h"
#include <iostream>

int main()
{
    std::string sql = "CREATE";

    std::cout << "Testing SQL: " << sql << std::endl;

    try
    {
        MiniDB::Lexer lexer(sql);
        auto tokens = lexer.tokenize();

        std::cout << "Tokens:" << std::endl;
        for (const auto &token : tokens)
        {
            if (token.type != MiniDB::TokenType::EOF_TOKEN)
            {
                std::cout << "  " << token.toString() << std::endl;
            }
        }

        // Debug: Check first token
        if (!tokens.empty() && tokens[0].type != MiniDB::TokenType::EOF_TOKEN)
        {
            std::cout << "\nFirst token details:" << std::endl;
            std::cout << "  Value: '" << tokens[0].value << "'" << std::endl;
            std::cout << "  Length: " << tokens[0].value.length() << std::endl;
            std::cout << "  First char: '" << tokens[0].value[0] << "' (ASCII: " << (int)tokens[0].value[0] << ")" << std::endl;
        }

        // Debug: Check if CREATE is in keywords
        std::cout << "\nDebugging:" << std::endl;
        auto &keywords = lexer.getKeywords();
        auto it = keywords.find("CREATE");
        if (it != keywords.end())
        {
            std::cout << "CREATE found in keywords map, token type: " << static_cast<int>(it->second) << std::endl;
        }
        else
        {
            std::cout << "CREATE NOT found in keywords map!" << std::endl;
        }

        MiniDB::Parser parser(tokens);
        auto statements = parser.parse();

        std::cout << "Parsed successfully! Statements: " << statements.size() << std::endl;
    }
    catch (const std::exception &e)
    {
        std::cerr << "Error: " << e.what() << std::endl;
        return 1;
    }

    return 0;
}
